﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using E2_WEBSITE.Code.Admin;
using E2_WEBSITE.Code;

namespace E2_WEBSITE.cp.admin.site
{
    public partial class editnews : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            if (Session["Authentication"] == null || Convert.ToInt32(Session["Authentication"]) != 0)
            {
                WebMsgBox.Show("Bạn phải là admin để có thể sử dụng chức năng này.");
                return;
            }
            try
            {
                NewsController controller = new NewsController();
                int nid = int.Parse(Page.Request["NewsId"].ToString());
                NewsInfo news = new NewsInfo(
                    (formView.FindControl("tbTitle") as TextBox).Text,
                    (formView.FindControl("editor") as OboutInc.Editor.Editor).Content,
                    Convert.ToInt32(Session["UserID"]),
                    DateTime.Now);

                if (controller.UpdateNews(nid, 1, news))
                {
                    WebMsgBox.Show("Cập nhật tin tức thành công.");
                }
            }
            catch (Exception)
            {
                Response.Redirect(Utilities.ErrorPagePath);
                throw;
            }
        }
    }
}
